package com.cts.training.ejb;

import javax.annotation.Resource;
import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;

@Stateless(name="EmployeeManagerName", mappedName="EmployeeManagerMappedName")
@Local(EmployeeManager.class)
public class EmployeeManagerImpl implements EmployeeManager {
	@Resource(mappedName="TrainingJMSConnectionFactory")
	ConnectionFactory connectionFactory;
	@Resource(mappedName="TrainingTopic")
	Topic topic;
	public void isAuthorized() {
		System.out.println("isAuthorized");
	}
	public void sendMessage(){
		try {
			Connection con = connectionFactory.createConnection();
			Session sess = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
			MessageProducer produce = sess.createProducer(topic);
			TextMessage msg = sess.createTextMessage();
			msg.setStringProperty("name","nirmal");
			produce.send(msg);
			con.close();
		} catch (JMSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
